﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Microsoft.Xna.Framework;
using Microsoft.Xna.Framework.Graphics;
using System.Xml;

namespace SpaceShooter.Settings
{
    public static partial class GameSettings
    {
        public static void ResetRenderStates(GraphicsDevice GraphicsDevice)
        {
            //SpriteBatch will refresh the render state, reset here
            GraphicsDevice.RenderState.AlphaBlendEnable = false;
            GraphicsDevice.RenderState.DepthBufferEnable = true;
            GraphicsDevice.RenderState.AlphaTestEnable = false;
        }

        public static Vector3 readVector(XmlTextReader XmlRdr, string name)
        {
            Vector3 vector = new Vector3();
            while (XmlRdr.Read())
            {
                if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == name)
                {
                    float[] values = new float[3];

                    for (int i = 0; i < 3; )
                    {
                        XmlRdr.Read();
                        if (XmlRdr.NodeType == XmlNodeType.Element)
                        {
                            values[i] = XmlRdr.ReadElementContentAsFloat();
                            i++;
                        }
                    }

                    vector.X = values[0];
                    vector.Y = values[1];
                    vector.Z = values[2];
                    return vector;
                }
            }
            return vector;
        }

        public static float readFloat(XmlTextReader XmlRdr, string name)
        {
            while (XmlRdr.Read())
            {
                if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == name)
                {
                    return XmlRdr.ReadElementContentAsFloat();
                }
            }
            return 0.0f;
        }

        public static int readInt(XmlTextReader XmlRdr, string name)
        {
            while (XmlRdr.Read())
            {
                if (XmlRdr.NodeType == XmlNodeType.Element && XmlRdr.Name == name)
                {
                    return XmlRdr.ReadElementContentAsInt();
                }
            }
            return 0;
        }
    }
}
